package com.atguigu.tingshu.search.service.impl;

import cn.hutool.core.lang.Assert;
import com.atguigu.tingshu.album.AlbumFeignClient;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.AlbumInfo;
import com.atguigu.tingshu.search.service.ItemService;
import com.atguigu.tingshu.vo.album.AlbumStatVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadPoolExecutor;

@Slf4j
@Service
@SuppressWarnings({"all"})
public class ItemServiceImpl implements ItemService {

    @Autowired
    private AlbumFeignClient albumFeignClient;

    @Autowired
    private ThreadPoolExecutor threadPoolExecutor;

    @Override
    public Map<String, Object> albumInfoData(Long albumId) {
        //远程调用专辑服务获取专辑信息，专辑统计信息，专辑分类信息，主播信息
        //创建返回数据对象
        Map<String,Object> map = new ConcurrentHashMap<>();

        CompletableFuture<AlbumInfo> albumInfo1 = CompletableFuture.supplyAsync(() -> {
            //调用专辑服务
            //获取专辑信息
            AlbumInfo albumInfo = albumFeignClient.getAlbumInfo(albumId).getData();
            Assert.notNull(albumInfo, "专辑{}不存在", albumId);
            map.put("albumInfo", albumInfo);
            return albumInfo;
        }, threadPoolExecutor);


        //获取专辑统计信息
        Result<AlbumStatVo> albumStatVo = albumFeignClient.getAlbumStatVo(albumId);
        //获取专辑分类信息
        return null;
    }
}
